﻿#region Copyright Info

// 
// Majesty of Omega - The next evolution of macro management space strategy
// 
// Copyright 2007-2009 André Claaßen
// 
// This file is protected by the terms and conditions of the
// Microsoft Community License (Ms-CL 1.1), a copy of which should
// have been distributed along with this software. If not,
// you may find the license information at the following URL:
// 
// http://www.microsoft.com/resources/sharedsource/licensingbasics/communitylicense.mspx

#endregion

#region

using System.Collections.Generic;
using System.Windows.Documents;
using Majesty_of_Omega.GUI.Utility;
#if NUNIT
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using ClassInitialize = NUnit.Framework.TestFixtureSetUpAttribute;
using ClassCleanup = NUnit.Framework.TestFixtureTearDownAttribute;
#elif MBUNIT
using MbUnit.Framework;
using TestClass = MbUnit.Framework.TestFixtureAttribute;
using TestMethod = MbUnit.Framework.TestAttribute;
using TestInitialize = MbUnit.Framework.SetUpAttribute;
using TestCleanup = MbUnit.Framework.TearDownAttribute;
using ClassInitialize = MbUnit.Framework.TestFixtureSetUpAttribute;
using ClassCleanup = MbUnit.Framework.TestFixtureTearDownAttribute;
#else
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif


#endregion

namespace Test.Majesty_of_Omega.GUI.Util
{
    /// <summary>
    /// Test Class for <see cref="MooTextToInlineConverter"/>
    /// </summary>
    [TestClass]
    public class TestMooTextToInlineConverter
    {
        /// <summary>
        /// This function tests a simple text conversion to WPF <see cref="Inline"/>-Objects
        /// </summary>
        [TestMethod]
        public void TestSimpleTextConversion()
        {
            const string testText = @"    The quick brown fox jumps over the lazy river.";

            MooTextToInlineConverter inlineConverter = new MooTextToInlineConverter();
            var inlines = inlineConverter.ConvertMooTextToInlines(testText);
            Assert.AreEqual(1, inlines.Count, "1 Inline objects expected: Run Object");
            Assert.IsInstanceOfType(typeof(Run), inlines[0] );
            Run firstLine = (Run)inlines[0];
            Assert.AreEqual("The quick brown fox jumps over the lazy river.", firstLine.Text);
        }
 
        /// <summary>
        /// This function tests a simple text conversion to WPF <see cref="Inline"/>-Objects
        /// </summary>
        [TestMethod]
        public void TestComplexeTextConversion()
        {
            const string testText = @"    This is a first line/p " +
                                    "\r\n" +
                                    "    and this is the second line.";

            List<Inline> inlines = GetInlines(testText);
            Assert.AreEqual(3, inlines.Count, "3 Inline objects expected: two Runs and one LineBreak");
            Assert.IsTrue(inlines[0].GetType() ==  typeof(Run));
            Assert.IsTrue(inlines[1].GetType()== typeof(LineBreak));
            Assert.IsTrue(inlines[2].GetType()==typeof(Run));
            Run firstLine = (Run)inlines[0];
            Run secondLine = (Run)inlines[2];
            Assert.AreEqual("This is a first line", firstLine.Text);
            Assert.AreEqual("and this is the second line.", secondLine.Text);
        }

        /// <summary>
        /// Gets the inlines forom the MooTextToInlineConverter
        /// </summary>
        /// <param name="testText">The test text.</param>
        /// <returns></returns>
        private static List<Inline> GetInlines(string testText)
        {
            MooTextToInlineConverter inlineConverter = new MooTextToInlineConverter();
            return inlineConverter.ConvertMooTextToInlines(testText);
        }

        /// <summary>
        /// This function tests a simple hyperlink
        /// </summary>
        [TestMethod]
        public void TestHyperLinkConversion()
        {
            const string testText = @"look at http://www.google.de for me";

            var inlines = GetInlines(testText);
            Assert.AreEqual(3, inlines.Count, "3 inline objects expeted. 2 runs and a hypertext");
        }
    }
}